import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:my_app/common/ui/ui_adapter.dart';
import 'package:my_app/r.dart';
import 'package:my_app/widget/input/DelInput.dart';
import 'LoginController.dart';

class LoginPage extends GetView<LoginController> {
  @override
  Widget build(BuildContext context) {
    controller;
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      body: Container(
        child: Stack(
          children: [
            Container(
              height: Get.height * 0.45,
              decoration: BoxDecoration(
                gradient: new LinearGradient(
                  begin: const FractionalOffset(0.5, 0.0),
                  end: const FractionalOffset(0.5, 1.0),
                  colors: <Color>[Colors.blueAccent, Colors.blue],
                ),
              ),
              child: Row(
                children: [
                  FlutterLogo(
                    size: 100,
                  ),
                  SizedBox(
                    width: 50,
                  ),
                  Text('Login', style: Theme.of(context).textTheme.headline2),
                ],
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: Get.height * .35, left: getWidth(20), right: getWidth(20)),
              child: Container(
                height: getHeight(300),
                child: Card(
                  child: Column(
                    children: [
                      _buildUserName(),
                      _buildPassword(),
                      _buildButton(text: "登陆", color: Colors.blueAccent, onPressed: () => controller.login()),
                      _buildButton(text: "注册", color: Colors.green, onPressed: () => controller.register()),
                    ],
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildButton({String text, Color color, VoidCallback onPressed}) {
    return Container(
      padding: EdgeInsets.only(left: getWidth(50), right: getWidth(50), top: getHeight(10)),
      child: MaterialButton(
        // highlightColor: Colors.green,
        hoverColor: Colors.green,
        minWidth: getWidth(200),
        height: getHeight(38),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50)),
        color: color,
        onPressed: onPressed,
        child: Text(text),
      ),
    );
  }

  Widget _buildPassword() {
    return Container(
      margin: EdgeInsets.only(
        top: auto(20),
        left: auto(50),
        right: auto(50),
        bottom: auto(10),
      ),
      child: DelInputWidget(
        controller: controller.passwordController.value,
        hintText: '请输入密码',
        icon: Icons.admin_panel_settings,
        onChanged: (value) {},
        isPassword: true,
      ),
    );
  }

  Widget _buildUserName() {
    return Container(
      margin: EdgeInsets.only(
        top: auto(30),
        left: auto(50),
        right: auto(50),
        bottom: auto(10),
      ),
      child: Obx(() {
        return DelInputWidget(
          controller: controller.userNameController.value,
          isShowDelIcon: controller.hasdeleteIcon.value,
          hintText: '请输入用户名',
          icon: Icons.person,
          onChanged: (value) {},
          isPassword: false,
        );
      }),
    );
  }
}
